package personal.learn.test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.stream.Collectors;

/**
 * 牛牛找工作
 *
 * @author Chai yansheng
 * @create 2019/8/18
 **/
public class CattleFindJob {

    public static void printMap(Map<Integer, Integer> dp) {
        dp.forEach((k, v) -> {
            System.out.println("key:" + k + "\tvalue:" + v);
        });
    }
    public static void doFindJob(Map<Integer, Integer> dp, List<Map.Entry<Integer,Integer>> a, int m) {
        int []ai = new int[100000];
        List<Map.Entry<Integer, Integer>> dpList = new ArrayList<Map.Entry<Integer, Integer>>(dp.entrySet());
        int i = 0, j = 0;
        while (i < m) {
            while (j < dpList.size() && dpList.get(j).getKey() <= a.get(i).getValue()) {
                j++;
            }
            ai[a.get(i).getKey()] = dpList.get(j - 1).getValue();
            i++;
        }
        for (i = 0; i < m; i++) {
            System.out.println(ai[i]);
        }
    }
    public static void main(String[] args) {
        int n,m;
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();
        Map<Integer, Integer> dp = new TreeMap<>();
        Map<Integer, Integer> aMap = new TreeMap<>();
        // int []a = new int[100000];
        for (int i = 0; i < n; i++) {
            Integer di = in.nextInt();
            Integer pi = in.nextInt();
            if (dp.get(di) == null) {
                dp.put(di, pi);
            } else if (dp.get(di) != null && dp.get(di) < pi) {
                dp.put(di, pi);
            }
        }
        for (int i = 0; i < m; i++) {
            int ai = in.nextInt();
            aMap.put(i, ai);
        }
        /*List<Map.Entry<Integer,Integer>> list = new ArrayList<Map.Entry<Integer,Integer>>(aMap.entrySet());
        Collections.sort(list,new Comparator<Map.Entry<Integer,Integer>>() {
            //升序排序
            public int compare(Map.Entry<Integer, Integer> o1,
                               Map.Entry<Integer, Integer> o2) {
                return o1.getValue().compareTo(o2.getValue());
            }

        });*/
        List<Map.Entry<Integer,Integer>> list = aMap.entrySet().stream()
                .sorted((entry1, entry2) -> entry1.getValue().compareTo(entry2.getValue()))
                .collect(Collectors.toList());
        //printMap(dp);
        //System.out.println("==============");
        doFindJob(dp, list, m);
    }
}
/*
6 3
200 20
1 100
100 5
10 1000
10 200
1000000000 1001
1000000000 10 9*/
